package cn.foolishbird.hamal.frame.bsassert.info;

import java.util.HashMap;
import java.util.Map;

/**
 * 错误信息接口
 *
 * @author Eric
 * @version 1.0
 * @date 2019-12-13
 */
public interface RstInfo {

    String CODE = "code";

    String CONTENT = "content";

    String DATA = "data";

    String ERROR = "messageError";


    /**
     * 状态码
     *
     * @param
     * @return int
     * @throws
     * @author Eric
     * @date 2020/4/12
     **/
    int code();

    /**
     * 状态说明
     *
     * @param
     * @return java.lang.String
     * @throws
     * @author Eric
     * @date 2020/4/12
     **/
    String content();

    /**
     * 数据
     *
     * @param
     * @return java.lang.Object
     * @throws
     * @author Eric
     * @date 2020/4/12
     **/
    Object data();


    /**
     * 错误信息
     *
     * @param
     * @return java.lang.String
     * @throws
     * @author Eric
     * @date 2020/9/29
     **/
    String errorMessage();


    static Map<String, Object> toMap(RstInfo info) {
        Map<String, Object> rst = new HashMap<>(16);
        rst.put(CODE, info.code());
        rst.put(CONTENT, info.content());
        rst.put(DATA, info.data());
        rst.put(ERROR, info.errorMessage());
        return rst;
    }

    static Map<String, Object> toMap(RstInfo rstInfo, Exception ex) {
        Map<String, Object> rst = new HashMap<>(16);
        rst.put(CODE, rstInfo.code());
        rst.put(CONTENT, rstInfo.content());
        rst.put(DATA, new Object());
        rst.put(ERROR, ex.getMessage());
        return rst;
    }

}
